package com.ag.dgm.dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import com.ag.bean.TbAdviceWay;
import com.ag.common.IDUtil;

public class TbAdviceWayDAO extends com.ag.dao.TbAdviceWayDAO {

	private Session session;
	Transaction tx =null;
	@Override
	public void delete(TbAdviceWay persistentInstance) {
		String hql = "update TbAdviceWay t set t.a=" + IDUtil.DELETE
				+ " where t.awId=" + persistentInstance.getAwId();
		session = (Session) this.getSessionFactory().openSession();
		try {
			tx = session.beginTransaction();
			Query query = session.createQuery(hql);
			int count = query.executeUpdate();
			tx.commit();
		} catch (HibernateException e) {
			e.printStackTrace();
			if(tx.isActive()){
				try{
					tx.rollback();
				}catch (HibernateException e2) {
					e2.printStackTrace();
				}
			}
		} finally {
			session.close();
		}
	}

	@Override
	public List<TbAdviceWay> findAll() {
		return super.findByA(IDUtil.PRESERVE);
	}
}
